// pages/userlook-list/deallook.js
const App = getApp();
import Dialog from '../../weapp/dialog/dialog'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    deviceList: [],    //列表
    deviceTotal: 0,    //总数
    devicePages: 0,     //总页数
    deviceIndex: 1,      //当前页 
    searchLoading: false, //加载更多
    deviceNoData: false,  //暂无更多
    searchLoadingComplete: false, //加载到底部
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  deleteItem(e) {
    let _this = this
    wx.showModal({
      title: '是否确定删除',
      success: (res) => {
        if (res.cancel) {

        } else {
          App._post_form(`Customer/orderDel`, {
            order_id:e.currentTarget.dataset.id
          }, function (result) {
            if (result.code === 0) {
              _this.onShow()
            }
          })
        }
      }
    })

    /*
    Dialog.confirm({
      title: '标题',
      message: '是否进行该操作？',
    })
      .then(() => {
        App._post_form(`Customer/orderDel`, {
          order_id:e.currentTarget.dataset.id
        }, function (result) {
          if (result.code === 0) {
            _this.onShow()
          }
        })
      })
      .catch(() => {
        // on cancel
      });
      */
  },
  handleToDetail(e){
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `../detail/index?id=${id}`,
    })
  },
  handleToTher(e) {
    const { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: `./detail?type=look&id=${id}`,
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getCustomersList()
  },
  /**
   * 获取客户列表数据
   */
  getCustomersList() {
    let _this = this
    wx.showLoading({
      title: '加载中...',
    })
    App._post_form('DataDetails/dataDetails', {
      page: _this.data.deviceIndex,
      data_type: 'turnover_list'
    }, function (result) {
      wx.hideLoading()
      // 响应无数据 则提示无数据
      //_this.filterList(result.data.list)
      let Result = result.data.list
      if (_this.data.deviceIndex == 1 && Result.length == 0) {
        console.log('没有')
        _this.setData({
          deviceNoData: true,
          searchLoading: false,
          searchLoadingComplete: false
        })
      }
      if (Result.length) {
        _this.data.deviceTotal = result.data.count
        _this.data.devicePages = result.data.total_page
        let deviceListTemp = [];
        if (_this.data.deviceIndex > 1) {
          deviceListTemp = _this.data.deviceList.concat(Result);
          console.log(deviceListTemp)
          _this.setData({
            searchLoading: true, //"正在载入更多"显示
          });
        } else {
          deviceListTemp = Result;
        }
        _this.setData({
          deviceList: deviceListTemp, //获取数据数组
          deviceNoData: false //“没有数据”隐藏
        });
      }
      console.log(_this.data.topData)

    });

  },
  onReachBottom: function () {
    // 页面触底时执行
    var _this = this;

    if (_this.data.deviceIndex < _this.data.devicePages) {
      _this.setData({
        deviceIndex: _this.data.deviceIndex + 1,   //每次触发触底事件，把deviceIndex+1
      });
      _this.getCustomersList();
    } else if (_this.data.deviceIndex == _this.data.devicePages) {
      _this.setData({
        searchLoadingComplete: true, //“已加载全部”显示
        searchLoading: false, //"正在载入更多"隐藏
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
this.onShow()
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})